package ua.org.extjsbuilder.editors;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;

public class ColorManager {
	public static final RGB KEYWORD = new RGB(0x7f,0x00,0x55);

	public static final RGB COMMENT = new RGB(0x6c,0x86,0x1e);

	public static final RGB DEFAULT = new RGB(0x33,0x33,0x33);
	
	protected Map<RGB,Color> colorsTable;

	ColorManager(){
		colorsTable = new HashMap<RGB,Color>(10);
	}
	
	public void dispose() {
		Iterator<Color> e = colorsTable.values().iterator();
		while (e.hasNext()){
			e.next().dispose();
		}
	}
	
	public Color getColor(RGB rgb) {
		Color color = colorsTable.get(rgb);
		if (color == null) {
			color = new Color(Display.getCurrent(), rgb);
			colorsTable.put(rgb, color);
		}
		return color;
	}
}
